package cn.myjerry.others.three;

import java.util.WeakHashMap;

/**
 * WeakHashMap 键为弱类型，gc运行立即回收
 * @author Jerry
 *
 */

public class WeakHashMapDemo {

	public static void main(String[] args) {
		WeakHashMap<String, String> map = new WeakHashMap<String, String>();
		//测试数据
		//常量池对象，不会被回收
		map.put("abc", "abc");
		map.put("def", "def");
		//gc运行 已被回收
		map.put(new String("myjerry"), "my");
		map.put(new String("Jerry"), "Jerry");
		System.out.println("gc运行前："+map.size());
		//通知回收
		System.gc();
		System.runFinalization();
		System.out.println("gc运行后："+map.size());
	}

}
